// console.log(location.search)
//获取id
const id = location.search.substring(4)

async function getData() {
    //获取当前美食的详情
    const res = await axios({
        method: 'GET',
        url: `http://124.223.14.236:3001/api/recipe/${id}`,
        
    })
    console.log(res)
    if (res.status === 200) {
        document.querySelector('.left img').src = `http://124.223.14.236:3001/public/${res.data.data.img}`
        document.querySelector('.right').innerHTML = `
        <h3>${res.data.data.name}</h3>
      <p>
        ${res.data.data.description}
      </p>
     
        `
    }else {
        return alert('获取失败')
    }
    //获取下面的美食列表
    const res1 = await axios({
        method: 'GET',
        url: 'http://124.223.14.236:3001/api/recipeInfo',
        params: {
            recipe_id: id
        }
    })
    // console.log(res1)
    if (res1.status === 200) {
        document.querySelector('.list-box').innerHTML = res1.data.data.map(item => {
            return `
            <li>
                <a href="detail.html?id=${item.id}">
                    <img src="http://124.223.14.236:3001/public/${item.img}" alt="" />
                    <h3>${item.title}</h3>
                </a>
            </li>
            `
        }).join('')
    }
}
getData()